package com.yeban.javase.day12.test;

import com.yeban.javase.day02.test03.Person;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/22
 *
 * BiFunction<T, U, R>练习
 * 将String类型的姓名、Integer类型的年龄，转换成Person对象
 */
public class BiFuction {

    public static Person3 exChange (BiFunction<String, Integer, Person3> bf, String s, Integer i) {
        Person3 person = bf.apply(s, i);
        return person;
    }

    public static void main(String[] args) {
        String s = "张三";
        Integer i = 18;
        
        // String姓名和Integer年龄转换为Person3
        Person3 p = exChange((name, age) -> {
            return new Person3(name, age);
        }, s, i);
        
        System.out.println(p);
        
        // 方法引用
        Person3 p2 = exChange(Person3::new, "李四", 25);
        System.out.println(p2);
    }
}

class Person3 {
    private String name;
    private int age;

    public Person3() {
    }

    public Person3(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Person3{name = " + name + ", age = " + age + "}";
    }
}
